<template>
	<view>
		<view class="sthconnect">
			<view v-for="(item , index) in form.info_list" :key="index" class="order_item">
				<view class="order_item_title">
					<view class="order_item_title_left">订单号：</view>
					<view class="order_item_title_right">{{item.code}}</view>
				</view>
				<view class="order_item_title">
					<view class="order_item_title_left">代购平台：</view>
					<view class="order_item_title_right">{{item.platform}}</view>
				</view>
				<view class="order_item_title">
					<view class="order_item_title_left">代购链接：</view>
					<view class="order_item_title_right">{{item.link}}</view>
				</view>
				<view class="order_item_title">
					<view class="order_item_title_left">商品名称：</view>
					<view class="order_item_title_right">{{item.remark}}</view>
				</view>
				<view class="order_item_title">
					<view class="order_item_title_left">联系微信：</view>
					<view class="order_item_title_right">{{item.style}}</view>
				</view>
				<view class="order_item_title">
					<view  class="order_item_title_left">价格：</view>
					<view class="order_item_title_right">{{item.price}}</view>
				</view>
			</view>
			<view v-if="form.username" class="sthconnectInfo">
				<view class="info_item">
					<span>
						<span class="xing"></span>
						<span class="info_item_title">收货人</span>
					</span>
					<div class="info_item_right">
						<input placeholder-class="input"  disabled v-model="form.username" class="input" type="text"  />
					</div>
				</view>
				<view class="info_item">
					<span>
						<span class="xing"></span>
						<span class="info_item_title">联系方式</span>
					</span>
					<div class="info_item_right">
						<input placeholder-class="input"  disabled v-model="form.phone" class="input" type="text"  />
					</div>
				</view>
				<view class="info_item">
					<span>
						<span class="xing"></span>
						<span class="info_item_title">身份证号码</span>
					</span>
					<div class="info_item_right">
						<input placeholder-class="input"  disabled v-model="form.idcode" class="input" type="text"  />
					</div>
				</view>
				<view class="info_item">
					<span>
						<span class="xing"></span>
						<span class="info_item_title">收货地址</span>
					</span>
					
					<div class="info_item_right">
						<span class="input" >
							{{`${form.province_name}-${form.city_name}-${form.area_name}-${form.address}`}}
						</span>
					</div>
				</view>
			</view>
		</view>
		
		
		
		<!-- <view  class="button_submit">
			
			<u-button  @click="onSubmit(1)" class="btns" :custom-style="{'background':'#90c0ff' ,color:'#fff'}"  :shape="'circle'" :hair-line="false" :ripple="true" ripple-bg-color="rgba(9, 82, 200, 0.15)">
				提交
			</u-button>
		</view> -->
	</view>
</template>

<script>
	import upload from '@/componts/upload/upload.vue';
	export default {
		components:{
		    upload
		},
		data() {
			return {
				title:'申请代拍',
				pop_show:false,
				type_text:'请选择寄往仓库',
				imgList:[],
				report_list:[],
				order_id:null,
				form:{
					"type2": "1", //1 代买 2代付
					"link": null,
					'style':null,//物品款式
					"name": null, //物品名
					'platform':null,//购买平台
					"num": null, //数量
					"remark": null, //备注信息
					status:0,
					"pic": null, //图片
				}
			}
		},
		onLoad(e) {
			if(e.id){
				// console.log('--------')
				this.order_id = e.id
				this.getInfo()
			}
		},
		onShow() {
			var token = uni.getStorageSync('token')
			if(!token){
				uni.setStorageSync('isModule' , true)
				uni.showModal({
					title: '登录',
					content: '登录后可使用完整功能',
					cancelText: "取消", // 取消按钮的文字  
					confirmText: "确认", // 确认按钮的文字  
					showCancel: true, // 是否显示取消按钮，默认为 true
					success: (res) => {
						uni.setStorageSync('isModule' , false)
					if(res.confirm) {  
						// console.log('comfirm') //点击确定之后执行的代码
						uni.navigateTo({
							url:'/pages/login/login'
						})
					} else {  
						
						uni.switchTab({
							url:'/pages/index/index'
						})
						}  
					} 
				})
				return
			}
		},
		methods: {
			// 预览图片
			previewImage(index , arr) {
			  uni.previewImage({
			    current: index, // 当前显示图片索引
			    urls: arr // 需要预览的图片http链接列表
			  });
			},
			getInfo(){
				var data = {
					id:this.order_id
				}
				this.$gugoApi.buy_detail(data).then(res=>{
					this.form = res.data
				})
			},
			openPop(){
				if(this.form.status>1){
					return
				}
				this.pop_show = true
			},
			onchange(e){
				this.type_text = this.list[e].text
				this.form.type = this.list[e].type
			},
			FileChange(e){
				this.imgList = e
			},
			dignyu(){
				return new Promise((resolve, reject) => {
					wx.requestSubscribeMessage({
					    tmplIds: [
							'LL09Z07c3pLTnLQotLfD8DYQm9SB6A-QQ1QW3eBop2M',//支付消息提醒
							'bjb55ZIOo1z7CjLTXkkqVSd_fe6WJLaqIjxtmihuZTI', //物流消息提醒
						],
					    success(res) {
							resolve(true)
					    },
						fail(err) {
							resolve(false)
						}
					})
				})
			},
			onSubmit(type){
				var isOk = true
				var toast = ''
				this.form.pic = this.imgList.join(',')
				// console.log(this.form)
				try{
					for(var key in this.form){
						if(!this.form[key]){
							if(key=='link'){
								toast="请输入代购链接"
								throw new Error(toast)
							} 
							if(key=='platform'){
								toast="请输入购买平台"
								throw new Error(toast)
							} 
							if(key=='name'){
								toast="请输入物品名称"
								throw new Error(toast)
							} 
							if(key=='num'){
								toast="请输入购买数量"
								throw new Error(toast)
							} 
							if(key=='style'){
								toast="请输入联系方式"
								throw new Error(toast)
							}
							if(key=='pic'){
								toast="请上传物品照片"
								throw new Error(toast)
							} 
						}
					}
				}catch(err){
					isOk = false
				}
				if(!isOk){
					uni.showToast({
						title:toast,
						icon:'none'
					})
					return
				}
				
				if(type==1){
					// 新增
					this.$wqzApi.Buy_add(this.form).then(res=>{
						uni.showToast({
							title:'提交成功',
							icon:'none'
						})
						setTimeout(()=>{
							uni.redirectTo({
								url:'/pages/order_other_list/order_other_list?current=0&type=1'
							})
						},1500)
					})
				}else{
					// 修改
					this.$wqzApi.buy_update(this.form).then(res=>{
						uni.showToast({	
							title:'提交成功',
							icon:'none'
						})
						setTimeout(()=>{
							uni.redirectTo({
								url:'/pages/order_other_list/order_other_list?current=0&type=1'
							})
						},1500)
					})
				}
			}
		}
	}
</script>

<style lang="scss" scoped>
	@import url(./Postage_order.css)
</style>
